This commit is contained in:
markiantorno 2020-04-02 22:46:49 -04:00
parent b0a15a11a2
commit 6e9b760b75
6 changed files with 161 additions and 53 deletions

View File

@ -88,10 +88,7 @@ import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.validation.cliutils.ComparisonUtils; import org.hl7.fhir.validation.cliutils.*;
import org.hl7.fhir.validation.cliutils.DisplayUtils;
import org.hl7.fhir.validation.cliutils.ParamUtils;
import org.hl7.fhir.validation.cliutils.Utils;
/** /**
* A executable class that will validate one or more FHIR resources against * A executable class that will validate one or more FHIR resources against
@ -224,7 +221,7 @@ public class Validator {
doDebug = true; doDebug = true;
} else if (args[i].equals("-sct")) { } else if (args[i].equals("-sct")) {
String s = args[++i]; String s = args[++i];
snomedCT = resolveSnomedCTCode(s); snomedCT = SnomedVersion.resolveSnomedCTCode(s);
} else if (args[i].equals("-recurse")) { } else if (args[i].equals("-recurse")) {
recursive = true; recursive = true;
} else if (args[i].equals("-locale")) { } else if (args[i].equals("-locale")) {
@ -278,23 +275,11 @@ public class Validator {
throw new Error("Specified " + args[i] + " without indicating ig file"); throw new Error("Specified " + args[i] + " without indicating ig file");
else { else {
String s = args[++i]; String s = args[++i];
if (s.equals("hl7.fhir.core")) { sv = Utils.getVersionFromIGName(null, s);
sv = "current"; if (sv == null) {
} 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
igs.add(s); igs.add(s);
} }
}
} else if (args[i].equals("-map")) { } else if (args[i].equals("-map")) {
if (map == null) { if (map == null) {
if (i + 1 == args.length) if (i + 1 == args.length)
@ -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() { private static String getGitBuild() {
return "??"; return "??";
} }

View File

@ -1,4 +1,33 @@
package org.hl7.fhir.validation.cliutils; package org.hl7.fhir.validation.cliutils;
import org.hl7.fhir.validation.Validator;
import java.util.*;
public class CliContext { public class CliContext {
private String map = null;
private List<String> igs = new ArrayList<String>();
private List<String> questionnaires = new ArrayList<String>();
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<String> profiles = new ArrayList<String>();
private Validator.EngineMode mode = Validator.EngineMode.VALIDATION;
private String output = null;
private Boolean canDoNative = null;
private List<String> sources = new ArrayList<String>();
private Map<String, String> locations = new HashMap<String, String>();
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;
} }

View File

@ -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]);
// }
// }

View File

@ -1,8 +1,10 @@
package org.hl7.fhir.validation.cliutils; package org.hl7.fhir.validation.cliutils;
import java.util.Arrays;
public class ParamUtils { public class ParamUtils {
/** TODO proper error checking, streams /**
* Checks the list of passed in params to see if it contains the passed in param. * Checks the list of passed in params to see if it contains the passed in param.
* *
* @param args Array of params to search. * @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. * @return {@link Boolean#TRUE} if the list contains the given param.
*/ */
public static boolean hasParam(String[] args, String param) { public static boolean hasParam(String[] args, String param) {
for (String a : args) return Arrays.asList(args).contains(param);
if (a.equals(param))
return true;
return false;
} }
/** TODO proper error checking, streams /**
* Fetches the vlaue for the passed in param from the provided list of params. * Fetches the vlaue for the passed in param from the provided list of params.
* *
* @param args Array of params to search. * @param args Array of params to search.

View File

@ -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<SnomedVersion> 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");
}
}
}

View File

@ -50,7 +50,9 @@ public class Utils {
* @return * @return
*/ */
public static String getVersionFromIGName(String defaultValue, String igFileName) { 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)); defaultValue = VersionUtilities.getCurrentPackageVersion(igFileName.substring(14));
} else if (igFileName.startsWith("hl7.fhir.r2.core#") || igFileName.equals("hl7.fhir.r2.core")) { } else if (igFileName.startsWith("hl7.fhir.r2.core#") || igFileName.equals("hl7.fhir.r2.core")) {
defaultValue = "1.0"; defaultValue = "1.0";
@ -66,7 +68,6 @@ public class Utils {
return defaultValue; return defaultValue;
} }
/** /**
* Triggers the validation engine tests to run. * Triggers the validation engine tests to run.
*/ */