Merge pull request #833 from hapifhir/gg-202206-fhirpath

fix bug counting children + fix issue with automatic string conversio…
This commit is contained in:
Grahame Grieve 2022-06-08 09:50:22 +10:00 committed by GitHub
commit 2b3f7e7143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 358 additions and 176 deletions

View File

@ -12,7 +12,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.utilities.SimpleHTTPClient; import org.hl7.fhir.utilities.SimpleHTTPClient;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult; import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.NpmPackage;
@ -132,12 +132,12 @@ public class PackageVisitor {
list.add(i.getId()); list.add(i.getId());
} }
JsonObject json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json"); JsonObject json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json");
for (JsonObject ig : JSONUtil.objects(json, "guides")) { for (JsonObject ig : JsonUtilities.objects(json, "guides")) {
list.add(JSONUtil.str(ig, "npm-name")); list.add(JsonUtilities.str(ig, "npm-name"));
} }
json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/package-feeds.json"); json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/package-feeds.json");
for (JsonObject feed : JSONUtil.objects(json, "feeds")) { for (JsonObject feed : JsonUtilities.objects(json, "feeds")) {
processFeed(list, JSONUtil.str(feed, "url")); processFeed(list, JsonUtilities.str(feed, "url"));
} }
return list; return list;

View File

@ -13,7 +13,7 @@ import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_50;
import org.hl7.fhir.convertors.factory.*; import org.hl7.fhir.convertors.factory.*;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.npm.NpmPackageIndexBuilder; import org.hl7.fhir.utilities.npm.NpmPackageIndexBuilder;
@ -167,7 +167,7 @@ public class NpmPackageVersionConverter {
private byte[] convertPackage(byte[] cnt) throws IOException { private byte[] convertPackage(byte[] cnt) throws IOException {
JsonObject json = JsonTrackingParser.parseJson(cnt); JsonObject json = JsonTrackingParser.parseJson(cnt);
currentVersion = json.getAsJsonArray("fhirVersions").get(0).getAsString(); currentVersion = json.getAsJsonArray("fhirVersions").get(0).getAsString();
String name = JSONUtil.str(json, "name"); String name = JsonUtilities.str(json, "name");
json.remove("name"); json.remove("name");
json.addProperty("name", name + "." + vCode); json.addProperty("name", name + "." + vCode);
json.remove("fhirVersions"); json.remove("fhirVersions");

View File

@ -22,7 +22,7 @@ import org.hl7.fhir.r4b.formats.IParser.OutputStyle;
import org.hl7.fhir.utilities.TextFile; 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.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData; import org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
@ -73,7 +73,7 @@ public class SHCParser extends ParserBase {
int i = 0; int i = 0;
for (JsonElement e : arr) { for (JsonElement e : arr) {
if (!(e instanceof JsonPrimitive)) { if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), "$.verifiableCredential["+i+"]", IssueType.STRUCTURE, "Wrong Property verifiableCredential in JSON Payload. Expected : String but found "+JSONUtil.type(e), IssueSeverity.ERROR); logError(line(e), col(e), "$.verifiableCredential["+i+"]", IssueType.STRUCTURE, "Wrong Property verifiableCredential in JSON Payload. Expected : String but found "+JsonUtilities.type(e), IssueSeverity.ERROR);
} else { } else {
list.add(e.getAsString()); list.add(e.getAsString());
} }
@ -117,7 +117,7 @@ public class SHCParser extends ParserBase {
int i = 0; int i = 0;
for (JsonElement e : type) { for (JsonElement e : type) {
if (!(e instanceof JsonPrimitive)) { if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), path+".type["+i+"]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found "+JSONUtil.type(e), IssueSeverity.ERROR); logError(line(e), col(e), path+".type["+i+"]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found "+JsonUtilities.type(e), IssueSeverity.ERROR);
} else { } else {
types.add(e.getAsString()); types.add(e.getAsString());
} }
@ -171,7 +171,7 @@ public class SHCParser extends ParserBase {
private boolean checkProperty(JsonObject obj, String path, String name, boolean required, String type) { private boolean checkProperty(JsonObject obj, String path, String name, boolean required, String type) {
JsonElement e = obj.get(name); JsonElement e = obj.get(name);
if (e != null) { if (e != null) {
String t = JSONUtil.type(e); String t = JsonUtilities.type(e);
if (!type.equals(t)) { if (!type.equals(t)) {
logError(line(e), col(e), path+"."+name, IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : "+type+" but found "+t, IssueSeverity.ERROR); logError(line(e), col(e), path+"."+name, IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : "+type+" but found "+t, IssueSeverity.ERROR);
} else { } else {
@ -275,7 +275,7 @@ public class SHCParser extends ParserBase {
} }
JWT res = new JWT(); JWT res = new JWT();
res.header = JsonTrackingParser.parseJson(headerJson); res.header = JsonTrackingParser.parseJson(headerJson);
if ("DEF".equals(JSONUtil.str(res.header, "zip"))) { if ("DEF".equals(JsonUtilities.str(res.header, "zip"))) {
payloadJson = inflate(payloadJson); payloadJson = inflate(payloadJson);
} }
res.payload = JsonTrackingParser.parse(TextFile.bytesToString(payloadJson), res.map, true); res.payload = JsonTrackingParser.parse(TextFile.bytesToString(payloadJson), res.map, true);

View File

@ -3744,7 +3744,7 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
} else if (Utilities.isAbsoluteUrl(u)) { } else if (Utilities.isAbsoluteUrl(u)) {
StructureDefinition sd = context.fetchResource(StructureDefinition.class, u); StructureDefinition sd = context.fetchResource(StructureDefinition.class, u);
if (sd != null) { if (sd != null && pkp != null) {
String disp = sd.hasTitle() ? sd.getTitle() : sd.getName(); String disp = sd.hasTitle() ? sd.getTitle() : sd.getName();
String ref = pkp.getLinkForProfile(null, sd.getUrl()); String ref = pkp.getLinkForProfile(null, sd.getUrl());
if (ref != null && ref.contains("|")) if (ref != null && ref.contains("|"))

View File

@ -1102,11 +1102,13 @@ public class Element extends Base {
public int countDescendents() { public int countDescendents() {
if (descendentCount > 0) { if (descendentCount > 0) {
return descendentCount; return descendentCount;
} else { } else if (children != null) {
descendentCount = children.size(); descendentCount = children.size();
for (Element e : children) { for (Element e : children) {
descendentCount = descendentCount + e.countDescendents(); descendentCount = descendentCount + e.countDescendents();
} }
} else {
descendentCount = 0;
} }
return descendentCount; return descendentCount;
} }

View File

@ -22,7 +22,7 @@ import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.utilities.TextFile; 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.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData; import org.hl7.fhir.utilities.json.JsonTrackingParser.LocationData;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
@ -73,7 +73,7 @@ public class SHCParser extends ParserBase {
int i = 0; int i = 0;
for (JsonElement e : arr) { for (JsonElement e : arr) {
if (!(e instanceof JsonPrimitive)) { if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), "$.verifiableCredential["+i+"]", IssueType.STRUCTURE, "Wrong Property verifiableCredential in JSON Payload. Expected : String but found "+JSONUtil.type(e), IssueSeverity.ERROR); logError(line(e), col(e), "$.verifiableCredential["+i+"]", IssueType.STRUCTURE, "Wrong Property verifiableCredential in JSON Payload. Expected : String but found "+JsonUtilities.type(e), IssueSeverity.ERROR);
} else { } else {
list.add(e.getAsString()); list.add(e.getAsString());
} }
@ -117,7 +117,7 @@ public class SHCParser extends ParserBase {
int i = 0; int i = 0;
for (JsonElement e : type) { for (JsonElement e : type) {
if (!(e instanceof JsonPrimitive)) { if (!(e instanceof JsonPrimitive)) {
logError(line(e), col(e), path+".type["+i+"]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found "+JSONUtil.type(e), IssueSeverity.ERROR); logError(line(e), col(e), path+".type["+i+"]", IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : String but found "+JsonUtilities.type(e), IssueSeverity.ERROR);
} else { } else {
types.add(e.getAsString()); types.add(e.getAsString());
} }
@ -171,7 +171,7 @@ public class SHCParser extends ParserBase {
private boolean checkProperty(JsonObject obj, String path, String name, boolean required, String type) { private boolean checkProperty(JsonObject obj, String path, String name, boolean required, String type) {
JsonElement e = obj.get(name); JsonElement e = obj.get(name);
if (e != null) { if (e != null) {
String t = JSONUtil.type(e); String t = JsonUtilities.type(e);
if (!type.equals(t)) { if (!type.equals(t)) {
logError(line(e), col(e), path+"."+name, IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : "+type+" but found "+t, IssueSeverity.ERROR); logError(line(e), col(e), path+"."+name, IssueType.STRUCTURE, "Wrong Property Type in JSON Payload. Expected : "+type+" but found "+t, IssueSeverity.ERROR);
} else { } else {
@ -275,7 +275,7 @@ public class SHCParser extends ParserBase {
} }
JWT res = new JWT(); JWT res = new JWT();
res.header = JsonTrackingParser.parseJson(headerJson); res.header = JsonTrackingParser.parseJson(headerJson);
if ("DEF".equals(JSONUtil.str(res.header, "zip"))) { if ("DEF".equals(JsonUtilities.str(res.header, "zip"))) {
payloadJson = inflate(payloadJson); payloadJson = inflate(payloadJson);
} }
res.payload = JsonTrackingParser.parse(TextFile.bytesToString(payloadJson), res.map, true); res.payload = JsonTrackingParser.parse(TextFile.bytesToString(payloadJson), res.map, true);

View File

@ -262,6 +262,7 @@ public class FHIRPathEngine {
private ProfileUtilities profileUtilities; private ProfileUtilities profileUtilities;
private String location; // for error messages private String location; // for error messages
private boolean allowPolymorphicNames; private boolean allowPolymorphicNames;
private boolean doImplicitStringConversion;
// if the fhir path expressions are allowed to use constants beyond those defined in the specification // if the fhir path expressions are allowed to use constants beyond those defined in the specification
// the application can implement them by providing a constant resolver // the application can implement them by providing a constant resolver
@ -447,6 +448,14 @@ public class FHIRPathEngine {
} }
public boolean isDoImplicitStringConversion() {
return doImplicitStringConversion;
}
public void setDoImplicitStringConversion(boolean doImplicitStringConversion) {
this.doImplicitStringConversion = doImplicitStringConversion;
}
// --- public API ------------------------------------------------------- // --- public API -------------------------------------------------------
/** /**
* Parse a path for later use using execute * Parse a path for later use using execute
@ -4211,14 +4220,16 @@ public class FHIRPathEngine {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) { if (focus.size() == 1) {
String f = convertToString(focus.get(0)); if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
if (Utilities.noString(f)) { String f = convertToString(focus.get(0));
result.add(new StringType("")); if (Utilities.noString(f)) {
} else { result.add(new StringType(""));
String t = convertToString(execute(context, focus, expr.getParameters().get(0), true)); } else {
String r = convertToString(execute(context, focus, expr.getParameters().get(1), true)); String t = convertToString(execute(context, focus, expr.getParameters().get(0), true));
String n = f.replace(t, r); String r = convertToString(execute(context, focus, expr.getParameters().get(1), true));
result.add(new StringType(n)); String n = f.replace(t, r);
result.add(new StringType(n));
}
} }
} else { } else {
throw makeException(expr, I18nConstants.FHIRPATH_NO_COLLECTION, "replace", focus.size()); throw makeException(expr, I18nConstants.FHIRPATH_NO_COLLECTION, "replace", focus.size());
@ -4233,7 +4244,9 @@ public class FHIRPathEngine {
String repl = convertToString(execute(context, focus, exp.getParameters().get(1), true)); String repl = convertToString(execute(context, focus, exp.getParameters().get(1), true));
if (focus.size() == 1 && !Utilities.noString(regex)) { if (focus.size() == 1 && !Utilities.noString(regex)) {
result.add(new StringType(convertToString(focus.get(0)).replaceAll(regex, repl)).noExtensions()); if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
result.add(new StringType(convertToString(focus.get(0)).replaceAll(regex, repl)).noExtensions());
}
} else { } else {
result.add(new StringType(convertToString(focus.get(0))).noExtensions()); result.add(new StringType(convertToString(focus.get(0))).noExtensions());
} }
@ -4249,7 +4262,7 @@ public class FHIRPathEngine {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
} else if (Utilities.noString(sw)) { } else if (Utilities.noString(sw)) {
result.add(new BooleanType(true).noExtensions()); result.add(new BooleanType(true).noExtensions());
} else { } else if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
if (focus.size() == 1 && !Utilities.noString(sw)) { if (focus.size() == 1 && !Utilities.noString(sw)) {
result.add(new BooleanType(convertToString(focus.get(0)).endsWith(sw)).noExtensions()); result.add(new BooleanType(convertToString(focus.get(0)).endsWith(sw)).noExtensions());
} else { } else {
@ -4919,14 +4932,16 @@ public class FHIRPathEngine {
String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true)); String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true));
if (focus.size() == 1 && !Utilities.noString(sw)) { if (focus.size() == 1 && !Utilities.noString(sw)) {
String st = convertToString(focus.get(0)); if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
if (Utilities.noString(st)) { String st = convertToString(focus.get(0));
result.add(new BooleanType(false).noExtensions()); if (Utilities.noString(st)) {
} else { result.add(new BooleanType(false).noExtensions());
Pattern p = Pattern.compile("(?s)" + sw); } else {
Matcher m = p.matcher(st); Pattern p = Pattern.compile("(?s)" + sw);
boolean ok = m.find(); Matcher m = p.matcher(st);
result.add(new BooleanType(ok).noExtensions()); boolean ok = m.find();
result.add(new BooleanType(ok).noExtensions());
}
} }
} else { } else {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
@ -4939,14 +4954,16 @@ public class FHIRPathEngine {
String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true)); String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true));
if (focus.size() == 1 && !Utilities.noString(sw)) { if (focus.size() == 1 && !Utilities.noString(sw)) {
String st = convertToString(focus.get(0)); if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
if (Utilities.noString(st)) { String st = convertToString(focus.get(0));
result.add(new BooleanType(false).noExtensions()); if (Utilities.noString(st)) {
} else { result.add(new BooleanType(false).noExtensions());
Pattern p = Pattern.compile("(?s)" + sw); } else {
Matcher m = p.matcher(st); Pattern p = Pattern.compile("(?s)" + sw);
boolean ok = m.matches(); Matcher m = p.matcher(st);
result.add(new BooleanType(ok).noExtensions()); boolean ok = m.matches();
result.add(new BooleanType(ok).noExtensions());
}
} }
} else { } else {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
@ -4962,7 +4979,7 @@ public class FHIRPathEngine {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
} else if (Utilities.noString(sw)) { } else if (Utilities.noString(sw)) {
result.add(new BooleanType(true).noExtensions()); result.add(new BooleanType(true).noExtensions());
} else { } else if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
String st = convertToString(focus.get(0)); String st = convertToString(focus.get(0));
if (Utilities.noString(st)) { if (Utilities.noString(st)) {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
@ -4981,7 +4998,7 @@ public class FHIRPathEngine {
private List<Base> funcLength(ExecutionContext context, List<Base> focus, ExpressionNode exp) { private List<Base> funcLength(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) { if (focus.size() == 1 && (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion)) {
String s = convertToString(focus.get(0)); String s = convertToString(focus.get(0));
result.add(new IntegerType(s.length()).noExtensions()); result.add(new IntegerType(s.length()).noExtensions());
} }
@ -5007,7 +5024,7 @@ public class FHIRPathEngine {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
} else if (Utilities.noString(sw)) { } else if (Utilities.noString(sw)) {
result.add(new BooleanType(true).noExtensions()); result.add(new BooleanType(true).noExtensions());
} else { } else if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
String s = convertToString(focus.get(0)); String s = convertToString(focus.get(0));
if (s == null) { if (s == null) {
result.add(new BooleanType(false).noExtensions()); result.add(new BooleanType(false).noExtensions());
@ -5020,7 +5037,7 @@ public class FHIRPathEngine {
private List<Base> funcLower(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException { private List<Base> funcLower(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) { if (focus.size() == 1 && (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion)) {
String s = convertToString(focus.get(0)); String s = convertToString(focus.get(0));
if (!Utilities.noString(s)) { if (!Utilities.noString(s)) {
result.add(new StringType(s.toLowerCase()).noExtensions()); result.add(new StringType(s.toLowerCase()).noExtensions());
@ -5031,7 +5048,7 @@ public class FHIRPathEngine {
private List<Base> funcUpper(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException { private List<Base> funcUpper(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) { if (focus.size() == 1 && (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion)) {
String s = convertToString(focus.get(0)); String s = convertToString(focus.get(0));
if (!Utilities.noString(s)) { if (!Utilities.noString(s)) {
result.add(new StringType(s.toUpperCase()).noExtensions()); result.add(new StringType(s.toUpperCase()).noExtensions());
@ -5042,7 +5059,7 @@ public class FHIRPathEngine {
private List<Base> funcToChars(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException { private List<Base> funcToChars(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>(); List<Base> result = new ArrayList<Base>();
if (focus.size() == 1) { if (focus.size() == 1 && (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion)) {
String s = convertToString(focus.get(0)); String s = convertToString(focus.get(0));
for (char c : s.toCharArray()) { for (char c : s.toCharArray()) {
result.add(new StringType(String.valueOf(c)).noExtensions()); result.add(new StringType(String.valueOf(c)).noExtensions());
@ -5059,7 +5076,7 @@ public class FHIRPathEngine {
result.add(new IntegerType(0).noExtensions()); result.add(new IntegerType(0).noExtensions());
} else if (Utilities.noString(sw)) { } else if (Utilities.noString(sw)) {
result.add(new IntegerType(0).noExtensions()); result.add(new IntegerType(0).noExtensions());
} else { } else if (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion) {
String s = convertToString(focus.get(0)); String s = convertToString(focus.get(0));
if (s == null) { if (s == null) {
result.add(new IntegerType(0).noExtensions()); result.add(new IntegerType(0).noExtensions());
@ -5080,7 +5097,7 @@ public class FHIRPathEngine {
i2 = Integer.parseInt(n2.get(0).primitiveValue()); i2 = Integer.parseInt(n2.get(0).primitiveValue());
} }
if (focus.size() == 1) { if (focus.size() == 1 && (focus.get(0).hasType(FHIR_TYPES_STRING) || doImplicitStringConversion)) {
String sw = convertToString(focus.get(0)); String sw = convertToString(focus.get(0));
String s; String s;
if (i1 < 0 || i1 >= sw.length()) { if (i1 < 0 || i1 >= sw.length()) {

View File

@ -71,7 +71,7 @@ public class SimpleHTTPClient {
public void checkThrowException() throws IOException { public void checkThrowException() throws IOException {
if (code >= 300) { if (code >= 300) {
String filename = Utilities.path("[tmp]", "fhir-http-"+(++counter)+".log"); String filename = Utilities.path("[tmp]", "fhir-http-"+(++counter)+".log");
if (content.length == 0) { if (content == null || content.length == 0) {
throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (no content)"); throw new IOException("Invalid HTTP response "+code+" from "+source+" ("+message+") (no content)");
} else { } else {
TextFile.bytesToFile(content, filename); TextFile.bytesToFile(content, filename);

View File

@ -1333,6 +1333,30 @@ public class Utilities {
return false; return false;
} }
public static boolean endsWithInList(String s, String... list) {
if (s == null) {
return false;
}
for (String l : list) {
if (s.endsWith(l)) {
return true;
}
}
return false;
}
public static boolean endsWithInList(String s, Collection<String> list) {
if (s == null) {
return false;
}
for (String l : list) {
if (s.endsWith(l)) {
return true;
}
}
return false;
}
public static final int ONE_MB = 1024; public static final int ONE_MB = 1024;
public static final String GB = "Gb"; public static final String GB = "Gb";
public static final String MB = "Mb"; public static final String MB = "Mb";

View File

@ -45,7 +45,7 @@ import com.google.gson.JsonNull;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
public class JSONUtil { public class JsonUtilities {
public static JsonObject parse(String json) throws IOException { public static JsonObject parse(String json) throws IOException {
return JsonTrackingParser.parseJson(json); return JsonTrackingParser.parseJson(json);
@ -155,4 +155,15 @@ public class JSONUtil {
return "String"; return "String";
} }
public static List<String> strings(JsonArray arr) {
List<String> res = new ArrayList<String>();
for (int i = 0; i < arr.size(); i++) {
JsonElement n = arr.get(i);
if (n.isJsonPrimitive()) {
res.add(n.getAsString());
}
}
return res;
}
} }

View File

@ -42,7 +42,7 @@ import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.TextFile; 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.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.npm.NpmPackage.NpmPackageFolder; import org.hl7.fhir.utilities.npm.NpmPackage.NpmPackageFolder;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -414,14 +414,14 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
log(" done."); log(" done.");
} }
pck = loadPackageInfo(packRoot); pck = loadPackageInfo(packRoot);
if (!id.equals(JSONUtil.str(npm.getNpm(), "name")) || !v.equals(JSONUtil.str(npm.getNpm(), "version"))) { if (!id.equals(JsonUtilities.str(npm.getNpm(), "name")) || !v.equals(JsonUtilities.str(npm.getNpm(), "version"))) {
if (!id.equals(JSONUtil.str(npm.getNpm(), "name"))) { if (!id.equals(JsonUtilities.str(npm.getNpm(), "name"))) {
npm.getNpm().addProperty("original-name", JSONUtil.str(npm.getNpm(), "name")); npm.getNpm().addProperty("original-name", JsonUtilities.str(npm.getNpm(), "name"));
npm.getNpm().remove("name"); npm.getNpm().remove("name");
npm.getNpm().addProperty("name", id); npm.getNpm().addProperty("name", id);
} }
if (!v.equals(JSONUtil.str(npm.getNpm(), "version"))) { if (!v.equals(JsonUtilities.str(npm.getNpm(), "version"))) {
npm.getNpm().addProperty("original-version", JSONUtil.str(npm.getNpm(), "version")); npm.getNpm().addProperty("original-version", JsonUtilities.str(npm.getNpm(), "version"));
npm.getNpm().remove("version"); npm.getNpm().remove("version");
npm.getNpm().addProperty("version", v); npm.getNpm().addProperty("version", v);
} }
@ -566,8 +566,8 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
checkBuildLoaded(); checkBuildLoaded();
for (JsonElement n : buildInfo) { for (JsonElement n : buildInfo) {
JsonObject o = (JsonObject) n; JsonObject o = (JsonObject) n;
if (packageId.equals(JSONUtil.str(o, "package-id"))) { if (packageId.equals(JsonUtilities.str(o, "package-id"))) {
return JSONUtil.str(o, "url"); return JsonUtilities.str(o, "url");
} }
} }
return null; return null;
@ -577,8 +577,8 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
checkBuildLoaded(); checkBuildLoaded();
for (JsonElement n : buildInfo) { for (JsonElement n : buildInfo) {
JsonObject o = (JsonObject) n; JsonObject o = (JsonObject) n;
if (!specList.containsKey(JSONUtil.str(o, "package-id"))) { if (!specList.containsKey(JsonUtilities.str(o, "package-id"))) {
specList.put(JSONUtil.str(o, "package-id"), JSONUtil.str(o, "url")); specList.put(JsonUtilities.str(o, "package-id"), JsonUtilities.str(o, "url"));
} }
} }
} }
@ -604,8 +604,8 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
for (String pf : listPackages()) { for (String pf : listPackages()) {
if (new File(Utilities.path(cacheFolder, pf, "package", "package.json")).exists()) { if (new File(Utilities.path(cacheFolder, pf, "package", "package.json")).exists()) {
JsonObject npm = JsonTrackingParser.parseJsonFile(Utilities.path(cacheFolder, pf, "package", "package.json")); JsonObject npm = JsonTrackingParser.parseJsonFile(Utilities.path(cacheFolder, pf, "package", "package.json"));
if (canonicalUrl.equals(JSONUtil.str(npm, "canonical"))) { if (canonicalUrl.equals(JsonUtilities.str(npm, "canonical"))) {
return JSONUtil.str(npm, "name"); return JsonUtilities.str(npm, "name");
} }
} }
} }
@ -624,14 +624,14 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
if (buildInfo != null) { if (buildInfo != null) {
for (JsonElement n : buildInfo) { for (JsonElement n : buildInfo) {
JsonObject o = (JsonObject) n; JsonObject o = (JsonObject) n;
if (canonical.equals(JSONUtil.str(o, "url"))) { if (canonical.equals(JsonUtilities.str(o, "url"))) {
return JSONUtil.str(o, "package-id"); return JsonUtilities.str(o, "package-id");
} }
} }
for (JsonElement n : buildInfo) { for (JsonElement n : buildInfo) {
JsonObject o = (JsonObject) n; JsonObject o = (JsonObject) n;
if (JSONUtil.str(o, "url").startsWith(canonical + "/ImplementationGuide/")) { if (JsonUtilities.str(o, "url").startsWith(canonical + "/ImplementationGuide/")) {
return JSONUtil.str(o, "package-id"); return JsonUtilities.str(o, "package-id");
} }
} }
} }
@ -644,7 +644,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
try { try {
String url = ciList.get(id); String url = ciList.get(id);
JsonObject json = JsonTrackingParser.fetchJson(Utilities.pathURL(url, "package.manifest.json")); JsonObject json = JsonTrackingParser.fetchJson(Utilities.pathURL(url, "package.manifest.json"));
String currDate = JSONUtil.str(json, "date"); String currDate = JsonUtilities.str(json, "date");
String packDate = p.date(); String packDate = p.date();
if (!currDate.equals(packDate)) { if (!currDate.equals(packDate)) {
return null; // nup, we need a new copy return null; // nup, we need a new copy
@ -740,13 +740,13 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
throw new FHIRException("Error fetching package directly (" + pv + "), or fetching package list for " + id + " from " + pu + ": " + e1.getMessage(), e1); throw new FHIRException("Error fetching package directly (" + pv + "), or fetching package list for " + id + " from " + pu + ": " + e1.getMessage(), e1);
} }
} }
if (!id.equals(JSONUtil.str(json, "package-id"))) if (!id.equals(JsonUtilities.str(json, "package-id")))
throw new FHIRException("Package ids do not match in " + pu + ": " + id + " vs " + JSONUtil.str(json, "package-id")); throw new FHIRException("Package ids do not match in " + pu + ": " + id + " vs " + JsonUtilities.str(json, "package-id"));
for (JsonElement e : json.getAsJsonArray("list")) { for (JsonElement e : json.getAsJsonArray("list")) {
JsonObject vo = (JsonObject) e; JsonObject vo = (JsonObject) e;
if (v.equals(JSONUtil.str(vo, "version"))) { if (v.equals(JsonUtilities.str(vo, "version"))) {
aurl = Utilities.pathURL(JSONUtil.str(vo, "path"), "package.tgz"); aurl = Utilities.pathURL(JsonUtilities.str(vo, "path"), "package.tgz");
String u = Utilities.pathURL(JSONUtil.str(vo, "path"), "package.tgz"); String u = Utilities.pathURL(JsonUtilities.str(vo, "path"), "package.tgz");
return new InputStreamWithSrc(fetchFromUrlSpecific(u, true), u, v); return new InputStreamWithSrc(fetchFromUrlSpecific(u, true), u, v);
} }
} }
@ -771,12 +771,12 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
} }
String pu = Utilities.pathURL(url, "package-list.json"); String pu = Utilities.pathURL(url, "package-list.json");
JsonObject json = JsonTrackingParser.fetchJson(pu); JsonObject json = JsonTrackingParser.fetchJson(pu);
if (!id.equals(JSONUtil.str(json, "package-id"))) if (!id.equals(JsonUtilities.str(json, "package-id")))
throw new FHIRException("Package ids do not match in " + pu + ": " + id + " vs " + JSONUtil.str(json, "package-id")); throw new FHIRException("Package ids do not match in " + pu + ": " + id + " vs " + JsonUtilities.str(json, "package-id"));
for (JsonElement e : json.getAsJsonArray("list")) { for (JsonElement e : json.getAsJsonArray("list")) {
JsonObject vo = (JsonObject) e; JsonObject vo = (JsonObject) e;
if (JSONUtil.bool(vo, "current")) { if (JsonUtilities.bool(vo, "current")) {
return JSONUtil.str(vo, "version"); return JsonUtilities.str(vo, "version");
} }
} }

View File

@ -67,7 +67,7 @@ import org.hl7.fhir.utilities.SimpleHTTPClient;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult; import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.npm.NpmPackage.ITransformingLoader; import org.hl7.fhir.utilities.npm.NpmPackage.ITransformingLoader;
import org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformationSorter; import org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformationSorter;
@ -113,12 +113,12 @@ public class NpmPackage {
public PackageResourceInformation(String root, JsonObject fi) throws IOException { public PackageResourceInformation(String root, JsonObject fi) throws IOException {
super(); super();
id = JSONUtil.str(fi, "id"); id = JsonUtilities.str(fi, "id");
type = JSONUtil.str(fi, "resourceType"); type = JsonUtilities.str(fi, "resourceType");
url = JSONUtil.str(fi, "url"); url = JsonUtilities.str(fi, "url");
version = JSONUtil.str(fi, "version"); version = JsonUtilities.str(fi, "version");
filename = Utilities.path(root, JSONUtil.str(fi, "filename")); filename = Utilities.path(root, JsonUtilities.str(fi, "filename"));
supplements = JSONUtil.str(fi, "supplements"); supplements = JsonUtilities.str(fi, "supplements");
} }
public String getId() { public String getId() {
return id; return id;
@ -144,8 +144,8 @@ public class NpmPackage {
@Override @Override
public int compare(JsonObject o0, JsonObject o1) { public int compare(JsonObject o0, JsonObject o1) {
String v0 = JSONUtil.str(o0, "version"); String v0 = JsonUtilities.str(o0, "version");
String v1 = JSONUtil.str(o1, "version"); String v1 = JsonUtilities.str(o1, "version");
return v0.compareTo(v1); return v0.compareTo(v1);
} }
} }
@ -185,8 +185,8 @@ public class NpmPackage {
this.index = index; this.index = index;
for (JsonElement e : index.getAsJsonArray("files")) { for (JsonElement e : index.getAsJsonArray("files")) {
JsonObject file = (JsonObject) e; JsonObject file = (JsonObject) e;
String type = JSONUtil.str(file, "resourceType"); String type = JsonUtilities.str(file, "resourceType");
String name = JSONUtil.str(file, "filename"); String name = JsonUtilities.str(file, "filename");
if (!types.containsKey(type)) if (!types.containsKey(type))
types.put(type, new ArrayList<>()); types.put(type, new ArrayList<>());
types.get(type).add(name); types.get(type).add(name);
@ -326,7 +326,8 @@ public class NpmPackage {
} }
public static boolean isInternalExemptFile(File f) { public static boolean isInternalExemptFile(File f) {
return Utilities.existsInList(f.getName(), ".git", ".svn") || Utilities.existsInList(f.getName(), "package-list.json"); return Utilities.existsInList(f.getName(), ".git", ".svn", ".DS_Store") || Utilities.existsInList(f.getName(), "package-list.json") ||
Utilities.endsWithInList(f.getName(), ".tgz");
} }
private void loadSubFolders(String rootPath, File dir) throws IOException { private void loadSubFolders(String rootPath, File dir) throws IOException {
@ -552,7 +553,7 @@ public class NpmPackage {
if (folder.index != null) { if (folder.index != null) {
for (JsonElement e : folder.index.getAsJsonArray("files")) { for (JsonElement e : folder.index.getAsJsonArray("files")) {
JsonObject fi = e.getAsJsonObject(); JsonObject fi = e.getAsJsonObject();
if (Utilities.existsInList(JSONUtil.str(fi, "resourceType"), types)) { if (Utilities.existsInList(JsonUtilities.str(fi, "resourceType"), types)) {
res.add(new PackageResourceInformation(folder.folder.getAbsolutePath(), fi)); res.add(new PackageResourceInformation(folder.folder.getAbsolutePath(), fi));
} }
} }
@ -625,19 +626,19 @@ public class NpmPackage {
List<JsonObject> matches = new ArrayList<>(); List<JsonObject> matches = new ArrayList<>();
for (JsonElement e : f.index.getAsJsonArray("files")) { for (JsonElement e : f.index.getAsJsonArray("files")) {
JsonObject file = (JsonObject) e; JsonObject file = (JsonObject) e;
if (canonical.equals(JSONUtil.str(file, "url"))) { if (canonical.equals(JsonUtilities.str(file, "url"))) {
if (version != null && version.equals(JSONUtil.str(file, "version"))) { if (version != null && version.equals(JsonUtilities.str(file, "version"))) {
return load("package", JSONUtil.str(file, "filename")); return load("package", JsonUtilities.str(file, "filename"));
} else if (version == null) { } else if (version == null) {
matches.add(file); matches.add(file);
} }
} }
if (matches.size() > 0) { if (matches.size() > 0) {
if (matches.size() == 1) { if (matches.size() == 1) {
return load("package", JSONUtil.str(matches.get(0), "filename")); return load("package", JsonUtilities.str(matches.get(0), "filename"));
} else { } else {
Collections.sort(matches, new IndexVersionSorter()); Collections.sort(matches, new IndexVersionSorter());
return load("package", JSONUtil.str(matches.get(matches.size()-1), "filename")); return load("package", JsonUtilities.str(matches.get(matches.size()-1), "filename"));
} }
} }
} }
@ -697,7 +698,7 @@ public class NpmPackage {
* @return * @return
*/ */
public String name() { public String name() {
return JSONUtil.str(npm, "name"); return JsonUtilities.str(npm, "name");
} }
/** /**
@ -705,15 +706,15 @@ public class NpmPackage {
* @return * @return
*/ */
public String id() { public String id() {
return JSONUtil.str(npm, "name"); return JsonUtilities.str(npm, "name");
} }
public String date() { public String date() {
return JSONUtil.str(npm, "date"); return JsonUtilities.str(npm, "date");
} }
public String canonical() { public String canonical() {
return JSONUtil.str(npm, "canonical"); return JsonUtilities.str(npm, "canonical");
} }
/** /**
@ -721,7 +722,7 @@ public class NpmPackage {
* @return * @return
*/ */
public String version() { public String version() {
return JSONUtil.str(npm, "version"); return JsonUtilities.str(npm, "version");
} }
/** /**
@ -729,11 +730,11 @@ public class NpmPackage {
* @return * @return
*/ */
public String fhirVersion() { public String fhirVersion() {
if ("hl7.fhir.core".equals(JSONUtil.str(npm, "name"))) if ("hl7.fhir.core".equals(JsonUtilities.str(npm, "name")))
return JSONUtil.str(npm, "version"); return JsonUtilities.str(npm, "version");
else if (JSONUtil.str(npm, "name").startsWith("hl7.fhir.r2.") || JSONUtil.str(npm, "name").startsWith("hl7.fhir.r2b.") || JSONUtil.str(npm, "name").startsWith("hl7.fhir.r3.") || else if (JsonUtilities.str(npm, "name").startsWith("hl7.fhir.r2.") || JsonUtilities.str(npm, "name").startsWith("hl7.fhir.r2b.") || JsonUtilities.str(npm, "name").startsWith("hl7.fhir.r3.") ||
JSONUtil.str(npm, "name").startsWith("hl7.fhir.r4.") || JSONUtil.str(npm, "name").startsWith("hl7.fhir.r4b.") || JSONUtil.str(npm, "name").startsWith("hl7.fhir.r5.")) JsonUtilities.str(npm, "name").startsWith("hl7.fhir.r4.") || JsonUtilities.str(npm, "name").startsWith("hl7.fhir.r4b.") || JsonUtilities.str(npm, "name").startsWith("hl7.fhir.r5."))
return JSONUtil.str(npm, "version"); return JsonUtilities.str(npm, "version");
else { else {
JsonObject dep = null; JsonObject dep = null;
if (npm.has("dependencies") && npm.get("dependencies").isJsonObject()) { if (npm.has("dependencies") && npm.get("dependencies").isJsonObject()) {
@ -778,11 +779,11 @@ public class NpmPackage {
} }
public String type() { public String type() {
return JSONUtil.str(npm, "type"); return JsonUtilities.str(npm, "type");
} }
public String description() { public String description() {
return JSONUtil.str(npm, "description"); return JsonUtilities.str(npm, "description");
} }
public String getPath() { public String getPath() {
@ -800,24 +801,24 @@ public class NpmPackage {
} }
public String homepage() { public String homepage() {
return JSONUtil.str(npm, "homepage"); return JsonUtilities.str(npm, "homepage");
} }
public String url() { public String url() {
return JSONUtil.str(npm, "url"); return JsonUtilities.str(npm, "url");
} }
public String title() { public String title() {
return JSONUtil.str(npm, "title"); return JsonUtilities.str(npm, "title");
} }
public String toolsVersion() { public String toolsVersion() {
return JSONUtil.str(npm, "tools-version"); return JsonUtilities.str(npm, "tools-version");
} }
public String license() { public String license() {
return JSONUtil.str(npm, "license"); return JsonUtilities.str(npm, "license");
} }
// /** // /**
@ -833,7 +834,7 @@ public class NpmPackage {
if (npm.has("url") && npm.get("url").isJsonPrimitive()) { if (npm.has("url") && npm.get("url").isJsonPrimitive()) {
return PackageHacker.fixPackageUrl(npm.get("url").getAsString()); return PackageHacker.fixPackageUrl(npm.get("url").getAsString());
} else { } else {
return JSONUtil.str(npm, "canonical"); return JsonUtilities.str(npm, "canonical");
} }
} }
@ -842,8 +843,8 @@ public class NpmPackage {
JsonArray files = f.index.getAsJsonArray("files"); JsonArray files = f.index.getAsJsonArray("files");
for (JsonElement e : files) { for (JsonElement e : files) {
JsonObject i = (JsonObject) e; JsonObject i = (JsonObject) e;
if (type.equals(JSONUtil.str(i, "resourceType")) && id.equals(JSONUtil.str(i, "id"))) { if (type.equals(JsonUtilities.str(i, "resourceType")) && id.equals(JsonUtilities.str(i, "id"))) {
return load("package", JSONUtil.str(i, "filename")); return load("package", JsonUtilities.str(i, "filename"));
} }
} }
return null; return null;
@ -858,8 +859,8 @@ public class NpmPackage {
JsonArray files = f.index.getAsJsonArray("files"); JsonArray files = f.index.getAsJsonArray("files");
for (JsonElement e : files) { for (JsonElement e : files) {
JsonObject i = (JsonObject) e; JsonObject i = (JsonObject) e;
if (type.equals(JSONUtil.str(i, "resourceType")) && id.equals(JSONUtil.str(i, "id"))) { if (type.equals(JsonUtilities.str(i, "resourceType")) && id.equals(JsonUtilities.str(i, "id"))) {
return load("example", JSONUtil.str(i, "filename")); return load("example", JsonUtilities.str(i, "filename"));
} }
} }
} }
@ -1094,7 +1095,7 @@ public class NpmPackage {
} }
public boolean isCore() { public boolean isCore() {
return Utilities.existsInList(JSONUtil.str(npm, "type"), "fhir.core", "Core"); return Utilities.existsInList(JsonUtilities.str(npm, "type"), "fhir.core", "Core");
} }
public boolean hasCanonical(String url) { public boolean hasCanonical(String url) {
@ -1107,8 +1108,8 @@ public class NpmPackage {
if (folder != null) { if (folder != null) {
for (JsonElement e : folder.index.getAsJsonArray("files")) { for (JsonElement e : folder.index.getAsJsonArray("files")) {
JsonObject o = (JsonObject) e; JsonObject o = (JsonObject) e;
if (u.equals(JSONUtil.str(o, "url"))) { if (u.equals(JsonUtilities.str(o, "url"))) {
if (v == null || v.equals(JSONUtil.str(o, "version"))) { if (v == null || v.equals(JsonUtilities.str(o, "version"))) {
return true; return true;
} }
} }
@ -1126,7 +1127,7 @@ public class NpmPackage {
if (Utilities.existsInList(name(), "fhir.test.data.r2", "fhir.test.data.r3", "fhir.test.data.r4", "fhir.tx.support.r2", "fhir.tx.support.r3", "fhir.tx.support.r4", "us.nlm.vsac")) { if (Utilities.existsInList(name(), "fhir.test.data.r2", "fhir.test.data.r3", "fhir.test.data.r4", "fhir.tx.support.r2", "fhir.tx.support.r3", "fhir.tx.support.r4", "us.nlm.vsac")) {
return true; return true;
} }
if (JSONUtil.bool(npm, "lazy-load")) { if (JsonUtilities.bool(npm, "lazy-load")) {
return true; return true;
} }
if (!hasFile("other", "spec.internals")) { if (!hasFile("other", "spec.internals")) {
@ -1136,7 +1137,7 @@ public class NpmPackage {
} }
public boolean isNotForPublication() { public boolean isNotForPublication() {
return JSONUtil.bool(npm, "notForPublication"); return JsonUtilities.bool(npm, "notForPublication");
} }
public InputStream load(PackageResourceInformation p) throws FileNotFoundException { public InputStream load(PackageResourceInformation p) throws FileNotFoundException {

View File

@ -9,7 +9,7 @@ import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
import org.hl7.fhir.utilities.TextFile; 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.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -81,12 +81,12 @@ public class PackageClient {
if (versions != null) { if (versions != null) {
for (String v : sorted(versions.keySet())) { for (String v : sorted(versions.keySet())) {
JsonObject obj = versions.getAsJsonObject(v); JsonObject obj = versions.getAsJsonObject(v);
res.add(new PackageInfo(JSONUtil.str(obj, "Name", "name"), res.add(new PackageInfo(JsonUtilities.str(obj, "Name", "name"),
JSONUtil.str(obj, "Version", "version"), JsonUtilities.str(obj, "Version", "version"),
JSONUtil.str(obj, "FhirVersion", "fhirVersion"), JsonUtilities.str(obj, "FhirVersion", "fhirVersion"),
JSONUtil.str(obj, "Description", "description"), JsonUtilities.str(obj, "Description", "description"),
JSONUtil.str(obj, "url"), JsonUtilities.str(obj, "url"),
JSONUtil.str(obj, "canonical"), JsonUtilities.str(obj, "canonical"),
address)); address));
} }
} }
@ -121,12 +121,12 @@ public class PackageClient {
JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?")+params.toString()); JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?")+params.toString());
for (JsonElement e : json) { for (JsonElement e : json) {
JsonObject obj = (JsonObject) e; JsonObject obj = (JsonObject) e;
res.add(new PackageInfo(JSONUtil.str(obj, "Name", "name"), res.add(new PackageInfo(JsonUtilities.str(obj, "Name", "name"),
JSONUtil.str(obj, "Version", "version"), JsonUtilities.str(obj, "Version", "version"),
JSONUtil.str(obj, "FhirVersion", "fhirVersion"), JsonUtilities.str(obj, "FhirVersion", "fhirVersion"),
JSONUtil.str(obj, "Description", "description"), JsonUtilities.str(obj, "Description", "description"),
JSONUtil.str(obj, "url"), JsonUtilities.str(obj, "url"),
JSONUtil.str(obj, "canonical"), JsonUtilities.str(obj, "canonical"),
address)); address));
} }
} catch (IOException e1) { } catch (IOException e1) {
@ -192,10 +192,10 @@ public class PackageClient {
} }
protected PackageInfo getPackageInfoFromJSON(JsonObject o, String name, String canonical, String fhirVersion) { protected PackageInfo getPackageInfoFromJSON(JsonObject o, String name, String canonical, String fhirVersion) {
String id = JSONUtil.str(o, "npm-name"); String id = JsonUtilities.str(o, "npm-name");
String pname = JSONUtil.str(o, "name"); String pname = JsonUtilities.str(o, "name");
String pcanonical = JSONUtil.str(o, "canonical"); String pcanonical = JsonUtilities.str(o, "canonical");
String description = JSONUtil.str(o, "description"); String description = JsonUtilities.str(o, "description");
boolean ok = true; boolean ok = true;
if (ok && !Utilities.noString(name)) { if (ok && !Utilities.noString(name)) {
ok = (pname != null && pname.contains(name)) || (description != null && description.contains(name)) || (id != null && id.contains(name)); ok = (pname != null && pname.contains(name)) || (description != null && description.contains(name)) || (id != null && id.contains(name));
@ -209,15 +209,15 @@ public class PackageClient {
if (ok) { if (ok) {
// if we can find something... // if we can find something...
for (JsonObject e : JSONUtil.objects(o, "editions")) { for (JsonObject e : JsonUtilities.objects(o, "editions")) {
if (fhirVersion == null || fhirVersion.equals(JSONUtil.str(e, "fhir-version"))) { if (fhirVersion == null || fhirVersion.equals(JsonUtilities.str(e, "fhir-version"))) {
String v = JSONUtil.str(e, "ig-version"); String v = JsonUtilities.str(e, "ig-version");
if (version == null || VersionUtilities.isThisOrLater(version, v)) { if (version == null || VersionUtilities.isThisOrLater(version, v)) {
version = v; version = v;
fVersion = e.getAsJsonArray("fhir-version").get(0).getAsString(); fVersion = e.getAsJsonArray("fhir-version").get(0).getAsString();
url = JSONUtil.str(e, "url"); url = JsonUtilities.str(e, "url");
String npmPackage = JSONUtil.str(e, "package"); String npmPackage = JsonUtilities.str(e, "package");
if (npmPackage != null && id == null) { if (npmPackage != null && id == null) {
id = npmPackage.substring(0, npmPackage.indexOf("#")); id = npmPackage.substring(0, npmPackage.indexOf("#"));
} }
@ -231,7 +231,7 @@ public class PackageClient {
public List<PackageInfo> listFromRegistry(String name, String canonical, String fhirVersion) throws IOException { public List<PackageInfo> listFromRegistry(String name, String canonical, String fhirVersion) throws IOException {
List<PackageInfo> result = new ArrayList<>(); List<PackageInfo> result = new ArrayList<>();
JsonObject packages = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json?nocache=" + System.currentTimeMillis()); JsonObject packages = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json?nocache=" + System.currentTimeMillis());
for (JsonObject o : JSONUtil.objects(packages, "guides")) { for (JsonObject o : JsonUtilities.objects(packages, "guides")) {
if (o.has("canonical")) { if (o.has("canonical")) {
final PackageInfo packageInfo = getPackageInfoFromJSON(o, name, canonical, fhirVersion); final PackageInfo packageInfo = getPackageInfoFromJSON(o, name, canonical, fhirVersion);
if (packageInfo.getVersion() != null) { if (packageInfo.getVersion() != null) {
@ -249,7 +249,7 @@ public class PackageClient {
JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?")+params.toString()); JsonArray json = fetchJsonArray(Utilities.pathURL(address, "catalog?")+params.toString());
for (JsonElement e : json) { for (JsonElement e : json) {
JsonObject obj = (JsonObject) e; JsonObject obj = (JsonObject) e;
list.add(JSONUtil.str(obj, "Name", "name")); list.add(JsonUtilities.str(obj, "Name", "name"));
} }
} catch (IOException e1) { } catch (IOException e1) {
} }

View File

@ -5,6 +5,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -27,7 +28,7 @@ public class PackageHacker {
private static boolean useSecureReferences = false; private static boolean useSecureReferences = false;
public static void main(String[] args) throws FileNotFoundException, IOException { public static void main(String[] args) throws FileNotFoundException, IOException {
new PackageHacker().edit("/Users/grahamegrieve/work/test-cases/validator/swiss.mednet.fhir#0.5.0.tgz"); new PackageHacker().edit(args[0]);
} }
private void edit(String name) throws FileNotFoundException, IOException { private void edit(String name) throws FileNotFoundException, IOException {
@ -39,7 +40,14 @@ public class PackageHacker {
System.out.println("Altering Package "+f.getAbsolutePath()); System.out.println("Altering Package "+f.getAbsolutePath());
System.out.println(nice(pck.getNpm())); System.out.println(nice(pck.getNpm()));
change(pck.getNpm(), pck.getFolders().get("package").getContent()); change(pck.getNpm());
fixContent(pck.getFolders().get("package").getContent());
if (pck.getFolders().containsKey("openapi")) {
fixContent(pck.getFolders().get("openapi").getContent());
}
if (pck.getFolders().containsKey("xml")) {
fixContent(pck.getFolders().get("xml").getContent());
}
System.out.println("Revised Package"); System.out.println("Revised Package");
System.out.println("======================="); System.out.println("=======================");
@ -53,11 +61,16 @@ public class PackageHacker {
} }
} }
private void fixContent(Map<String, byte[]> content) {
fixVersionInContent(content);
}
private String nice(JsonObject json) { private String nice(JsonObject json) {
return new GsonBuilder().setPrettyPrinting().create().toJson(json); return new GsonBuilder().setPrettyPrinting().create().toJson(json);
} }
private void change(JsonObject npm, Map<String, byte[]> content) throws FileNotFoundException, IOException { private void change(JsonObject npm) throws FileNotFoundException, IOException {
fixVersions(npm); fixVersions(npm);
// npm.remove("notForPublication"); // npm.remove("notForPublication");
// npm.addProperty("url", "http://hl7.org/fhir/us/carin-rtpbc/STU1"); // npm.addProperty("url", "http://hl7.org/fhir/us/carin-rtpbc/STU1");
@ -67,21 +80,36 @@ public class PackageHacker {
// npm.addProperty("canonical", "http://hl7.org/fhir/us/davinci-drug-formulary"); // npm.addProperty("canonical", "http://hl7.org/fhir/us/davinci-drug-formulary");
//// npm.remove("description"); //// npm.remove("description");
//// npm.addProperty("description", "Group Wrapper that includes all the R4 packages"); //// npm.addProperty("description", "Group Wrapper that includes all the R4 packages");
// npm.remove("url"); npm.remove("url");
// npm.addProperty("url", "https://terminology.hl7.org/1.0.0/"); npm.addProperty("url", "http://hl7.org/fhir/R4B");
npm.remove("dependencies"); npm.remove("homepage");
JsonObject dep = new JsonObject(); npm.addProperty("homepage", "http://hl7.org/fhir/R4B");
npm.add("dependencies", dep); // npm.remove("dependencies");
dep.addProperty("hl7.fhir.r4.core", "4.0.1"); // JsonObject dep = new JsonObject();
dep.addProperty("ch.fhir.ig.ch-core", "2.0.0"); // npm.add("dependencies", dep);
dep.addProperty("ch.fhir.ig.ch-epr-term", "2.0.4"); // dep.addProperty("hl7.fhir.r4.core", "4.0.1");
dep.addProperty("ch.fhir.ig.ch-emed","current"); // dep.addProperty("ch.fhir.ig.ch-core", "2.0.0");
// dep.addProperty("ch.fhir.ig.ch-epr-term", "2.0.4");
// dep.addProperty("ch.fhir.ig.ch-emed","current");
// dep.addProperty("hl7.fhir.r4.examples", "4.0.1"); // dep.addProperty("hl7.fhir.r4.examples", "4.0.1");
// dep.addProperty("hl7.fhir.r4.expansions", "4.0.1"); // dep.addProperty("hl7.fhir.r4.expansions", "4.0.1");
// dep.addProperty("hl7.fhir.r4.elements", "4.0.1"); // dep.addProperty("hl7.fhir.r4.elements", "4.0.1");
} }
private void fixVersionInContent(Map<String, byte[]> content) {
for (String n : content.keySet()) {
if (n.endsWith(".json") || n.endsWith(".xml") || n.endsWith(".xsd")) {
String json = new String(content.get(n));
if (json.contains("4.3.0-cibuild") && !json.contains("4.3.0-snapshot1")) {
json = json.replace("4.3.0-cibuild", "4.3.0");
content.put(n, json.getBytes(StandardCharsets.UTF_8));
}
}
}
}
private void fixVersions(JsonObject npm) { private void fixVersions(JsonObject npm) {
npm.remove("fhirVersions"); npm.remove("fhirVersions");
JsonArray a = new JsonArray(); JsonArray a = new JsonArray();

View File

@ -9,7 +9,7 @@ import java.util.Set;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -63,7 +63,7 @@ public class PackageScanner {
} catch (Exception e) { } catch (Exception e) {
fv = "--"; fv = "--";
} }
output.add(pck.name()+"\t"+pck.version()+"\t"+pck.canonical()+"\t"+fv+'\t'+pck.fhirVersionList()+'\t'+JSONUtil.str(json, "kind")+'\t'+JSONUtil.str(json, "type")+'\t'+JsonTrackingParser.writeDense(json)); } catch (Exception e) { output.add(pck.name()+"\t"+pck.version()+"\t"+pck.canonical()+"\t"+fv+'\t'+pck.fhirVersionList()+'\t'+JsonUtilities.str(json, "kind")+'\t'+JsonUtilities.str(json, "type")+'\t'+JsonTrackingParser.writeDense(json)); } catch (Exception e) {
System.out.println("Error acessing "+pi.getId()+"#"+piv.getVersion()+": "+e.getMessage()); System.out.println("Error acessing "+pi.getId()+"#"+piv.getVersion()+": "+e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -0,0 +1,59 @@
package org.hl7.fhir.utilities.npm;
import java.io.File;
import java.io.IOException;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser;
import com.google.gson.JsonObject;
public class ResourceRenamer {
public static void main(String[] args) throws IOException {
new ResourceRenamer().processArg(new File(args[0]));
}
private void processArg(File file) throws IOException {
if (file.isDirectory()) {
process(file);
} else {
unbundle(file);
}
}
private void unbundle(File f) throws IOException {
JsonObject j = JsonTrackingParser.parseJson(f);
for (JsonObject e : JsonUtilities.objects(j, "entry")) {
JsonObject r = e.getAsJsonObject("resource");
String rt = r.get("resourceType").getAsString();
String id = r.get("id").getAsString();
String nn = Utilities.path(Utilities.getDirectoryForFile(f.getAbsolutePath()), rt+"-"+id+".json");
JsonTrackingParser.write(r, new File(nn), true);
}
}
private void process(File dir) {
for (File f : dir.listFiles()) {
if (f.getName().endsWith(".json")) {
try {
JsonObject j = JsonTrackingParser.parseJson(f);
String rt = j.get("resourceType").getAsString();
String id = j.get("id").getAsString();
String nn = Utilities.path(Utilities.getDirectoryForFile(f.getAbsolutePath()), rt+"-"+id+".json");
File nf = new File(nn);
if (!nn.equals(f.getAbsolutePath())) {
System.out.println("Rename "+f.getName()+" to "+nf.getName());
f.renameTo(nf);
}
} catch (Exception e) {
System.out.println("Error Processing "+f.getName()+" : "+e.getMessage());
}
}
}
}
}

View File

@ -24,7 +24,7 @@ import org.hl7.fhir.utilities.IniFile;
import org.hl7.fhir.utilities.TextFile; 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.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.NpmPackage;

View File

@ -8,7 +8,7 @@ import org.hl7.fhir.r5.elementmodel.SHCParser.JWT;
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities; import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;

View File

@ -158,6 +158,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
@Getter @Setter private boolean crumbTrails; @Getter @Setter private boolean crumbTrails;
@Getter @Setter private boolean allowExampleUrls; @Getter @Setter private boolean allowExampleUrls;
@Getter @Setter private boolean showMessagesFromReferences; @Getter @Setter private boolean showMessagesFromReferences;
@Getter @Setter private boolean doImplicitFHIRPathStringConversion;
@Getter @Setter private Locale locale; @Getter @Setter private Locale locale;
@Getter @Setter private List<ImplementationGuide> igs = new ArrayList<>(); @Getter @Setter private List<ImplementationGuide> igs = new ArrayList<>();
@Getter @Setter private List<String> extensionDomains = new ArrayList<>(); @Getter @Setter private List<String> extensionDomains = new ArrayList<>();
@ -623,6 +624,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IValidationP
validator.setQuestionnaireMode(questionnaireMode); validator.setQuestionnaireMode(questionnaireMode);
validator.setLevel(level); validator.setLevel(level);
validator.setNoUnicodeBiDiControlChars(noUnicodeBiDiControlChars); validator.setNoUnicodeBiDiControlChars(noUnicodeBiDiControlChars);
validator.setDoImplicitFHIRPathStringConversion(doImplicitFHIRPathStringConversion);
if (format == FhirFormat.SHC) { if (format == FhirFormat.SHC) {
igLoader.loadIg(getIgs(), getBinaries(), SHCParser.CURRENT_PACKAGE, true); igLoader.loadIg(getIgs(), getBinaries(), SHCParser.CURRENT_PACKAGE, true);
} }

View File

@ -46,6 +46,8 @@ public class CliContext {
private boolean noInvariants = false; private boolean noInvariants = false;
@JsonProperty("wantInvariantsInMessages") @JsonProperty("wantInvariantsInMessages")
private boolean wantInvariantsInMessages = false; private boolean wantInvariantsInMessages = false;
@JsonProperty("doImplicitFHIRPathStringConversion")
private boolean doImplicitFHIRPathStringConversion = false;
@JsonProperty("map") @JsonProperty("map")
private String map = null; private String map = null;
@ -233,6 +235,16 @@ public class CliContext {
return this; return this;
} }
@JsonProperty("doImplicitFHIRPathStringConversion")
public boolean isDoImplicitFHIRPathStringConversion() {
return doImplicitFHIRPathStringConversion;
}
@JsonProperty("doImplicitFHIRPathStringConversion")
public void setDoImplicitFHIRPathStringConversion(boolean doImplicitFHIRPathStringConversion) {
this.doImplicitFHIRPathStringConversion = doImplicitFHIRPathStringConversion;
}
@JsonProperty("locale") @JsonProperty("locale")
public String getLanguageCode() { public String getLanguageCode() {
return locale; return locale;

View File

@ -21,7 +21,7 @@ import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
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.VersionUtilities.VersionURLInfo; import org.hl7.fhir.utilities.VersionUtilities.VersionURLInfo;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.json.JsonTrackingParser; import org.hl7.fhir.utilities.json.JsonTrackingParser;
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.NpmPackage;
@ -165,8 +165,8 @@ public class StandAloneValidatorFetcher implements IValidatorResourceFetcher, IV
JsonObject json; JsonObject json;
try { try {
json = JsonTrackingParser.fetchJson("http://hl7.org/fhir/mappingspaces.json"); json = JsonTrackingParser.fetchJson("http://hl7.org/fhir/mappingspaces.json");
for (JsonObject ms : JSONUtil.objects(json, "spaces")) { for (JsonObject ms : JsonUtilities.objects(json, "spaces")) {
mappingsUris.add(JSONUtil.str(ms, "url")); mappingsUris.add(JsonUtilities.str(ms, "url"));
} }
} catch (IOException e) { } catch (IOException e) {
// frozen R4 list // frozen R4 list

View File

@ -354,6 +354,7 @@ public class ValidationService {
validator.setSnomedExtension(cliContext.getSnomedCTCode()); validator.setSnomedExtension(cliContext.getSnomedCTCode());
validator.setAssumeValidRestReferences(cliContext.isAssumeValidRestReferences()); validator.setAssumeValidRestReferences(cliContext.isAssumeValidRestReferences());
validator.setShowMessagesFromReferences(cliContext.isShowMessagesFromReferences()); validator.setShowMessagesFromReferences(cliContext.isShowMessagesFromReferences());
validator.setDoImplicitFHIRPathStringConversion(cliContext.isDoImplicitFHIRPathStringConversion());
validator.setNoExtensibleBindingMessages(cliContext.isNoExtensibleBindingMessages()); validator.setNoExtensibleBindingMessages(cliContext.isNoExtensibleBindingMessages());
validator.setNoUnicodeBiDiControlChars(cliContext.isNoUnicodeBiDiControlChars()); validator.setNoUnicodeBiDiControlChars(cliContext.isNoUnicodeBiDiControlChars());
validator.setNoInvariantChecks(cliContext.isNoInvariants()); validator.setNoInvariantChecks(cliContext.isNoInvariants());

View File

@ -68,6 +68,7 @@ public class Params {
public static final String SHOW_TIMES = "-show-times"; public static final String SHOW_TIMES = "-show-times";
public static final String ALLOW_EXAMPLE_URLS = "-allow-example-urls"; public static final String ALLOW_EXAMPLE_URLS = "-allow-example-urls";
public static final String OUTPUT_STYLE = "-output-style"; public static final String OUTPUT_STYLE = "-output-style";
public static final String DO_IMPLICIT_FHIRPATH_STRING_CONVERSION = "-implicit-fhirpath-string-conversions";
private static final Object JURISDICTION = "-jurisdiction"; private static final Object JURISDICTION = "-jurisdiction";
/** /**
@ -167,6 +168,8 @@ public class Params {
cliContext.setRecursive(true); cliContext.setRecursive(true);
} else if (args[i].equals(SHOW_MESSAGES_FROM_REFERENCES)) { } else if (args[i].equals(SHOW_MESSAGES_FROM_REFERENCES)) {
cliContext.setShowMessagesFromReferences(true); cliContext.setShowMessagesFromReferences(true);
} else if (args[i].equals(DO_IMPLICIT_FHIRPATH_STRING_CONVERSION)) {
cliContext.setDoImplicitFHIRPathStringConversion(true);
} else if (args[i].equals(LOCALE)) { } else if (args[i].equals(LOCALE)) {
if (i + 1 == args.length) { if (i + 1 == args.length) {
throw new Error("Specified -locale without indicating locale"); throw new Error("Specified -locale without indicating locale");

View File

@ -544,6 +544,14 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
this.crumbTrails = crumbTrails; this.crumbTrails = crumbTrails;
} }
public boolean isDoImplicitFHIRPathStringConversion() {
return fpe.isDoImplicitStringConversion();
}
public void setDoImplicitFHIRPathStringConversion(boolean doImplicitFHIRPathStringConversion) {
fpe.setDoImplicitStringConversion(doImplicitFHIRPathStringConversion);
}
private boolean allowUnknownExtension(String url) { private boolean allowUnknownExtension(String url) {
if ((allowExamples && (url.contains("example.org") || url.contains("acme.com"))) || url.contains("nema.org") || url.startsWith("http://hl7.org/fhir/tools/StructureDefinition/") || url.equals("http://hl7.org/fhir/StructureDefinition/structuredefinition-expression")) if ((allowExamples && (url.contains("example.org") || url.contains("acme.com"))) || url.contains("nema.org") || url.startsWith("http://hl7.org/fhir/tools/StructureDefinition/") || url.equals("http://hl7.org/fhir/StructureDefinition/structuredefinition-expression"))
// Added structuredefinition-expression explicitly because it wasn't defined in the version of the spec it needs to be used with // Added structuredefinition-expression explicitly because it wasn't defined in the version of the spec it needs to be used with

View File

@ -56,7 +56,7 @@ import org.hl7.fhir.r5.utils.validation.IValidatorResourceFetcher;
import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.ContainedReferenceValidationPolicy;
import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy; import org.hl7.fhir.r5.utils.validation.constants.ReferenceValidationPolicy;
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult; import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
import org.hl7.fhir.utilities.json.JSONUtil; import org.hl7.fhir.utilities.json.JsonUtilities;
import org.hl7.fhir.utilities.npm.NpmPackage; import org.hl7.fhir.utilities.npm.NpmPackage;
import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
@ -91,7 +91,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
manifest = (JsonObject) new com.google.gson.JsonParser().parse(contents); manifest = (JsonObject) new com.google.gson.JsonParser().parse(contents);
for (JsonElement e : manifest.getAsJsonArray("test-cases")) { for (JsonElement e : manifest.getAsJsonArray("test-cases")) {
JsonObject o = (JsonObject) e; JsonObject o = (JsonObject) e;
examples.put(JSONUtil.str(o, "name"), o); examples.put(JsonUtilities.str(o, "name"), o);
} }
List<String> names = new ArrayList<String>(examples.size()); List<String> names = new ArrayList<String>(examples.size());
@ -168,7 +168,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
if (content.has("use-test") && !content.get("use-test").getAsBoolean()) if (content.has("use-test") && !content.get("use-test").getAsBoolean())
return; return;
byte[] testCaseContent = TestingUtilities.loadTestResource("validator", JSONUtil.str(content, "file")).getBytes(StandardCharsets.UTF_8); byte[] testCaseContent = TestingUtilities.loadTestResource("validator", JsonUtilities.str(content, "file")).getBytes(StandardCharsets.UTF_8);
// load and process content // load and process content
FhirFormat fmt = determineFormat(content, testCaseContent); FhirFormat fmt = determineFormat(content, testCaseContent);
@ -177,7 +177,7 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
val.getContext().setClientRetryCount(4); val.getContext().setClientRetryCount(4);
val.setDebug(false); val.setDebug(false);
if (content.has("fetcher") && "standalone".equals(JSONUtil.str(content, "fetcher"))) { if (content.has("fetcher") && "standalone".equals(JsonUtilities.str(content, "fetcher"))) {
val.setFetcher(vCurr); val.setFetcher(vCurr);
vCurr.setFetcher(new StandAloneValidatorFetcher(vCurr.getPcm(), vCurr.getContext(), vCurr)); vCurr.setFetcher(new StandAloneValidatorFetcher(vCurr.getPcm(), vCurr.getContext(), vCurr));
} else { } else {
@ -337,8 +337,8 @@ public class ValidationTests implements IEvaluationContext, IValidatorResourceFe
private FhirFormat determineFormat(JsonObject config, byte[] cnt) throws IOException { private FhirFormat determineFormat(JsonObject config, byte[] cnt) throws IOException {
String name = JSONUtil.str(config, "file"); String name = JsonUtilities.str(config, "file");
return org.hl7.fhir.validation.ResourceChecker.checkIsResource(vCurr.getContext(), true, cnt, name, !JSONUtil.bool(config, "guess-format")); return org.hl7.fhir.validation.ResourceChecker.checkIsResource(vCurr.getContext(), true, cnt, name, !JsonUtilities.bool(config, "guess-format"));
} }
private List<StructureDefinition> asSdList(StructureDefinition sd) { private List<StructureDefinition> asSdList(StructureDefinition sd) {

View File

@ -203,3 +203,17 @@ v: {
"system" : "http://snomed.info/sct" "system" : "http://snomed.info/sct"
} }
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
{"code" : {
"system" : "http://snomed.info/sct",
"version" : "http://snomed.info/sct/11000172109/version/20210915",
"code" : "132037003",
"display" : "Pineywoods pig breed. Not."
}, "valueSet" :null, "lang":"null", "useServer":"true", "useClient":"true", "guessSystem":"false", "valueSetMode":"ALL_CHECKS", "versionFlexible":"false"}####
v: {
"display" : "Pineywoods pig",
"code" : "132037003",
"system" : "http://snomed.info/sct",
"severity" : "warning",
"error" : "The display \"Pineywoods pig breed. Not.\" is not a valid display for the code {http://snomed.info/sct}132037003 - should be one of ['Pineywoods pig', 'Pineywoods pig breed (organism)', 'Pineywoods pig breed'] (from http://tx.fhir.org/r4)"
}
-------------------------------------------------------------------------------------

View File

@ -19,7 +19,7 @@
<properties> <properties>
<hapi_fhir_version>5.4.0</hapi_fhir_version> <hapi_fhir_version>5.4.0</hapi_fhir_version>
<validator_test_case_version>1.1.100</validator_test_case_version> <validator_test_case_version>1.1.101-SNAPSHOT</validator_test_case_version>
<junit_jupiter_version>5.7.1</junit_jupiter_version> <junit_jupiter_version>5.7.1</junit_jupiter_version>
<junit_platform_launcher_version>1.7.1</junit_platform_launcher_version> <junit_platform_launcher_version>1.7.1</junit_platform_launcher_version>
<maven_surefire_version>3.0.0-M5</maven_surefire_version> <maven_surefire_version>3.0.0-M5</maven_surefire_version>