diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java index 3b799e59b..1c89ebd0c 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/ShExGenerator.java @@ -63,7 +63,7 @@ public class ShExGenerator { public boolean debugMode = false; // Used for Debugging and testing the code - public boolean processConstraints = true; // set to false - to skip processing constraints + public boolean processConstraints = false; // set to false - to skip processing constraints public ConstraintTranslationPolicy constraintPolicy = ConstraintTranslationPolicy.ALL; @@ -79,8 +79,8 @@ public class ShExGenerator { "PREFIX fhir: <$fhir$> \n" + "PREFIX fhirvs: <$fhirvs$>\n" + "PREFIX xsd: \n" + - "PREFIX rdf: \n" + - "BASE \n"; + "PREFIX rdf: \n"; + //"BASE \n"; private static String IMPORT_TEMPLATE = "IMPORT <$import$$fileExt$>\n"; @@ -486,8 +486,27 @@ public class ShExGenerator { if (required_value_sets.size() > 0) { shapeDefinitions.append("\n#---------------------- Value Sets ------------------------\n"); + List sortedVS = new ArrayList(); for (ValueSet vs : required_value_sets) - shapeDefinitions.append("\n").append(genValueSet(vs)); + sortedVS.add(genValueSet(vs)); + + Collections.sort(sortedVS, new Comparator() { + @Override + public int compare(String o1, String o2) { + try { + return StringUtils.substringBetween(o1, "fhirvs:", " ") + .compareTo(StringUtils.substringBetween(o2, "fhirvs:", " ")); + } + catch(Exception e){ + debug("SORT COMPARISON FAILED BETWEEN \n\t\t" + o1 + "\n\t\t and \n\t\t" + o2); + debug(e.getMessage()); + return 0; + } + } + }); + + for (String svs : sortedVS) + shapeDefinitions.append("\n").append(svs); } if ((unMappedFunctions != null) && (!unMappedFunctions.isEmpty())) { @@ -1426,8 +1445,14 @@ public class ShExGenerator { while (m.find()) { String tag = m.group(1); //System.out.println("FOUND IMPORT: " + tag); - if ((tag.indexOf(ONE_OR_MORE_PREFIX) == -1) && - (!imports.contains(tag))) + if (tag.indexOf(ONE_OR_MORE_PREFIX) != -1) { + tag = tag.substring(ONE_OR_MORE_PREFIX.length()); + } + + if ((tag.indexOf("_") != -1)||(tag.indexOf("_OR_") != -1)) + continue; + + if (!imports.contains(tag)) imports.add(tag); } } diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java index 328119052..7d5c0774d 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/ShexGeneratorTests.java @@ -46,10 +46,10 @@ public class ShexGeneratorTests { // If you un-comment the following lines, please comment all other lines in this method. // Test with processing constraints flag // ----------------- Uncomment following to testing/Debugging ----- -// boolean processConstraints = true; -// this.doTestSingleSD(name.toLowerCase(), cat, name, -// false, ShExGenerator.ConstraintTranslationPolicy.ALL, -// true, true, false, processConstraints); + // boolean processConstraints = false; + // this.doTestSingleSD(name.toLowerCase(), cat, name, + // false, ShExGenerator.ConstraintTranslationPolicy.ALL, + // true, true, false, processConstraints); } @Test @@ -145,7 +145,7 @@ public class ShexGeneratorTests { // BatchMode - All Shex Schemas in one single file false, // process constraints or not - true + false ); }