Skip to content

Commit

Permalink
Compile fix (#728)
Browse files Browse the repository at this point in the history
Co-authored-by: Grahame Grieve <[email protected]>
  • Loading branch information
grahamegrieve and Grahame Grieve authored Jul 27, 2023
1 parent 860657a commit 0f5f912
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -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<ValidationMessage> validate(CodeSystem cs, boolean forBuild) {
List<ValidationMessage> errors = new ArrayList<ValidationMessage>();

// 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<ValidationMessage> errors) {
Set<String> codes = new HashSet<String>();
checkCodes(codes, cs.getConcept(), "CodeSystem.where(id = '"+cs.getId()+"')", errors);
}

private void checkCodes(Set<String> codes, List<ConceptDefinitionComponent> list, String path, List<ValidationMessage> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("<html><head><title>"+title+"</title></head><body><h2>"+title+"</h2><pre>");
for (String s : tx.split("\\r?\\n|\\r")) {
if (s.startsWith("---") && s.endsWith("---")) {
f.println("</pre><hr/>");
String id = s.replace("-", "").trim();
f.println("<a name=\"l"+id+"\"> </a><h3>"+id+"</h3>");
f.println("<pre>");
} else {
f.println(s);
}
}
f.print(tx);
f.println("</pre></head></html>");
f.close();
Expand Down Expand Up @@ -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 ");
Expand Down Expand Up @@ -11372,16 +11381,16 @@ public static void main(String[] args) throws Exception {
System.out.println("or you can configure the proxy using -Dhttp.proxyHost=<ip> -Dhttp.proxyPort=<port> -Dhttps.proxyHost=<ip> -Dhttps.proxyPort=<port>");
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)");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<version>1.3.25-SNAPSHOT</version> <!-- See the note above -->

<properties>
<core_version>6.0.22</core_version>
<core_version>6.0.23-SNAPSHOT</core_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version>
<apache_poi_version>5.2.1</apache_poi_version>
<okhttp.version>4.10.0</okhttp.version>
Expand Down

0 comments on commit 0f5f912

Please sign in to comment.