diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Validator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Validator.java index edab6776a..af381bcd6 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Validator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/Validator.java @@ -88,10 +88,7 @@ import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.validation.ValidationMessage; -import org.hl7.fhir.validation.cliutils.ComparisonUtils; -import org.hl7.fhir.validation.cliutils.DisplayUtils; -import org.hl7.fhir.validation.cliutils.ParamUtils; -import org.hl7.fhir.validation.cliutils.Utils; +import org.hl7.fhir.validation.cliutils.*; /** * A executable class that will validate one or more FHIR resources against @@ -224,7 +221,7 @@ public class Validator { doDebug = true; } else if (args[i].equals("-sct")) { String s = args[++i]; - snomedCT = resolveSnomedCTCode(s); + snomedCT = SnomedVersion.resolveSnomedCTCode(s); } else if (args[i].equals("-recurse")) { recursive = true; } else if (args[i].equals("-locale")) { @@ -278,22 +275,10 @@ public class Validator { throw new Error("Specified " + args[i] + " without indicating ig file"); else { String s = args[++i]; - if (s.equals("hl7.fhir.core")) { - sv = "current"; - } else if (s.startsWith("hl7.fhir.core#")) { - sv = VersionUtilities.getCurrentPackageVersion(s.substring(14)); - } else if (s.startsWith("hl7.fhir.r2.core#") || s.equals("hl7.fhir.r2.core")) { - sv = "1.0"; - } else if (s.startsWith("hl7.fhir.r2b.core#") || s.equals("hl7.fhir.r2b.core")) { - sv = "1.4"; - } else if (s.startsWith("hl7.fhir.r3.core#") || s.equals("hl7.fhir.r3.core")) { - sv = "3.0"; - } else if (s.startsWith("hl7.fhir.r4.core#") || s.equals("hl7.fhir.r4.core")) { - sv = "4.0"; - } else if (s.startsWith("hl7.fhir.r5.core#") || s.equals("hl7.fhir.r5.core")) { - sv = "current"; - } else + sv = Utils.getVersionFromIGName(null, s); + if (sv == null) { igs.add(s); + } } } else if (args[i].equals("-map")) { if (map == null) { @@ -461,31 +446,6 @@ public class Validator { } } - public static String resolveSnomedCTCode(String s) { - String snomedCT; - if ("intl".equalsIgnoreCase(s)) - snomedCT = "900000000000207008"; - else if ("us".equalsIgnoreCase(s)) - snomedCT = "731000124108"; - else if ("uk".equalsIgnoreCase(s)) - snomedCT = "999000041000000102"; - else if ("au".equalsIgnoreCase(s)) - snomedCT = "32506021000036107"; - else if ("ca".equalsIgnoreCase(s)) - snomedCT = "20611000087101"; - else if ("nl".equalsIgnoreCase(s)) - snomedCT = "11000146104"; - else if ("se".equalsIgnoreCase(s)) - snomedCT = "45991000052106"; - else if ("es".equalsIgnoreCase(s)) - snomedCT = "449081005"; - else if ("dk".equalsIgnoreCase(s)) - snomedCT = "554471000005108"; - else - throw new Error("Snomed edition '" + s + "' not known"); - return snomedCT; - } - private static String getGitBuild() { return "??"; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/CliContext.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/CliContext.java index d09882b8b..63661c8fe 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/CliContext.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/CliContext.java @@ -1,4 +1,33 @@ package org.hl7.fhir.validation.cliutils; +import org.hl7.fhir.validation.Validator; + +import java.util.*; + public class CliContext { + + private String map = null; + private List igs = new ArrayList(); + private List questionnaires = new ArrayList(); + private String txServer = "http://tx.fhir.org"; + private boolean doNative = false; + private boolean anyExtensionsAllowed = true; + private boolean hintAboutNonMustSupport = false; + private boolean recursive = false; + private Locale locale = null; + private List profiles = new ArrayList(); + private Validator.EngineMode mode = Validator.EngineMode.VALIDATION; + private String output = null; + private Boolean canDoNative = null; + private List sources = new ArrayList(); + private Map locations = new HashMap(); + private String sv = "current"; + private String txLog = null; + private String mapLog = null; + private String lang = null; + private String fhirpath = null; + private String snomedCT = "900000000000207008"; + private String targetVer = null; + private boolean doDebug = false; + private boolean assumeValidRestReferences = false; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamArg.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamArg.java new file mode 100644 index 000000000..b27ac9050 --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamArg.java @@ -0,0 +1,81 @@ +package org.hl7.fhir.validation.cliutils; + +public enum ParamArg { + VERSION("-version"), + OUTPUT("-output"), + PROXY("-proxy"), + PROFILE("-profile"), + QUESTIONNAIRE("-questionnaire"), + NATIVE("-native"), + ASSUME_VALID_REST_REF("-assumeValidRestReferences"), + DEBUG("-debug"), + SCT("-sct"), + RECURSE("-recurse"), + LOCALE("-locale"), + STRICT_EXTENSIONS("-strictExtensions"), + HINT_ABOUT_NON_MUST_SUPPORT("-hintAboutNonMustSupport"), + TO_VERSION("-to-version"), + DO_NATIVE("-do-native"), + NO_NATIVE("-no-native"), + TRANSFORM("-transform"), + NARRATIVE("-narrative"), + SNAPSHOT("-snapshot"), + SCAN("-scan"), + TERMINOLOGY("-tx"), + TERMINOLOGY_LOG("-txLog"); + + private final String code; + + ParamArg(String code) { + this.code = code; + } + +} + + +// } else if (args[i].equals("-log")) { +// if (i + 1 == args.length) +// throw new Error("Specified -log without indicating file"); +// else +// mapLog = args[++i]; +// } else if (args[i].equals("-language")) { +// if (i + 1 == args.length) +// throw new Error("Specified -language without indicating language"); +// else +// lang = args[++i]; +// } else if (args[i].equals("-ig") || args[i].equals("-defn")) { +// if (i + 1 == args.length) +// throw new Error("Specified " + args[i] + " without indicating ig file"); +// else { +// String s = args[++i]; +// sv = Utils.getVersionFromIGName(null, s); +// if (sv == null) { +// igs.add(s); +// } +// } +// } else if (args[i].equals("-map")) { +// if (map == null) { +// if (i + 1 == args.length) +// throw new Error("Specified -map without indicating map file"); +// else +// map = args[++i]; +// } else { +// throw new Exception("Can only nominate a single -map parameter"); +// } +// } else if (args[i].startsWith("-x")) { +// i++; +// } else if (args[i].equals("-convert")) { +// mode = EngineMode.CONVERT; +// } else if (args[i].equals("-fhirpath")) { +// mode = EngineMode.FHIRPATH; +// if (fhirpath == null) +// if (i + 1 == args.length) +// throw new Error("Specified -fhirpath without indicating a FHIRPath expression"); +// else +// fhirpath = args[++i]; +// else +// throw new Exception("Can only nominate a single -fhirpath parameter"); +// } else { +// sources.add(args[i]); +// } +// } \ No newline at end of file diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamUtils.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamUtils.java index 23bbc55fc..32913524d 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamUtils.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/ParamUtils.java @@ -1,8 +1,10 @@ package org.hl7.fhir.validation.cliutils; +import java.util.Arrays; + public class ParamUtils { - /** TODO proper error checking, streams + /** * Checks the list of passed in params to see if it contains the passed in param. * * @param args Array of params to search. @@ -10,13 +12,10 @@ public class ParamUtils { * @return {@link Boolean#TRUE} if the list contains the given param. */ public static boolean hasParam(String[] args, String param) { - for (String a : args) - if (a.equals(param)) - return true; - return false; + return Arrays.asList(args).contains(param); } - /** TODO proper error checking, streams + /** * Fetches the vlaue for the passed in param from the provided list of params. * * @param args Array of params to search. diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/SnomedVersion.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/SnomedVersion.java new file mode 100644 index 000000000..ea26fbfa6 --- /dev/null +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/SnomedVersion.java @@ -0,0 +1,38 @@ +package org.hl7.fhir.validation.cliutils; + +import java.util.Arrays; +import java.util.Optional; + +public enum SnomedVersion { + INTL("intl", "900000000000207008"), + US("us", "731000124108"), + UK("uk", "999000041000000102"), + AU("au", "32506021000036107"), + CA("ca", "20611000087101"), + NL("nl", "11000146104"), + SE("se", "45991000052106"), + ES("es", "449081005"), + DK("dk", "554471000005108"); + + private static final String DEFAULT_CODE = "900000000000207008"; + + private final String lang; + private final String code; + + SnomedVersion(String lang, String code) { + this.lang = lang; + this.code = code; + } + + public static String resolveSnomedCTCode(String s) { + String foundCode; + Optional opt = Arrays.stream(values()) + .filter(v -> v.lang.equals(s)) + .findFirst(); + if (opt.isPresent()) { + return opt.get().code; + } else { + throw new Error("Snomed edition '" + s + "' not known"); + } + } +} diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/Utils.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/Utils.java index 4ff8169fe..37cd63218 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/Utils.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cliutils/Utils.java @@ -50,7 +50,9 @@ public class Utils { * @return */ public static String getVersionFromIGName(String defaultValue, String igFileName) { - if (igFileName.startsWith("hl7.fhir.core#")) { + if (igFileName.equals("hl7.fhir.core")) { + defaultValue = "current"; + } else if (igFileName.startsWith("hl7.fhir.core#")) { defaultValue = VersionUtilities.getCurrentPackageVersion(igFileName.substring(14)); } else if (igFileName.startsWith("hl7.fhir.r2.core#") || igFileName.equals("hl7.fhir.r2.core")) { defaultValue = "1.0"; @@ -66,7 +68,6 @@ public class Utils { return defaultValue; } - /** * Triggers the validation engine tests to run. */