Skip to content

Commit

Permalink
introduce new cliContext option doNotFetchUnknownProfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dehall committed Jan 16, 2024
1 parent 13dd587 commit 8bfba3d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class CliContext {
private HtmlInMarkdownCheck htmlInMarkdownCheck = HtmlInMarkdownCheck.WARNING;
@JsonProperty("allowDoubleQuotesInFHIRPath")
private boolean allowDoubleQuotesInFHIRPath = false;
@JsonProperty("doNotFetchUnknownProfiles")
private boolean doNotFetchUnknownProfiles = false;
@JsonProperty("checkIPSCodes")
private boolean checkIPSCodes;
@JsonProperty("langTransform")
Expand Down Expand Up @@ -328,6 +330,16 @@ public void setAllowDoubleQuotesInFHIRPath(boolean allowDoubleQuotesInFHIRPath)
this.allowDoubleQuotesInFHIRPath = allowDoubleQuotesInFHIRPath;
}

@JsonProperty("doNotFetchUnknownProfiles")
public boolean isDoNotFetchUnknownProfiles() {
return doNotFetchUnknownProfiles;
}

@JsonProperty("doNotFetchUnknownProfiles")
public void setDoNotFetchUnknownProfiles(boolean doNotFetchUnknownProfiles) {
this.doNotFetchUnknownProfiles = doNotFetchUnknownProfiles;
}

@JsonProperty("checkIPSCodes")
public boolean isCheckIPSCodes() {
return checkIPSCodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ protected ValidationEngine buildValidationEngine( CliContext cliContext, String
validationEngine.setForPublication(cliContext.isForPublication());
validationEngine.setShowTimes(cliContext.isShowTimes());
validationEngine.setAllowExampleUrls(cliContext.isAllowExampleUrls());
StandAloneValidatorFetcher fetcher = new StandAloneValidatorFetcher(validationEngine.getPcm(), validationEngine.getContext(), validationEngine);
validationEngine.setFetcher(fetcher);
validationEngine.getContext().setLocator(fetcher);
if (!cliContext.isDoNotFetchUnknownProfiles()) {
StandAloneValidatorFetcher fetcher = new StandAloneValidatorFetcher(validationEngine.getPcm(), validationEngine.getContext(), validationEngine);
validationEngine.setFetcher(fetcher);
validationEngine.getContext().setLocator(fetcher);
}
validationEngine.getBundleValidationRules().addAll(cliContext.getBundleValidationRules());
validationEngine.setJurisdiction(CodeSystemUtilities.readCoding(cliContext.getJurisdiction()));
TerminologyCache.setNoCaching(cliContext.isNoInternalCaching());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class Params {
public static final String SRC_LANG = "-src-lang";
public static final String TGT_LANG = "-tgt-lang";
public static final String ALLOW_DOUBLE_QUOTES = "-allow-double-quotes-in-fhirpath";
public static final String DO_NOT_FETCH_UNKNOWN_PROFILES = "-do-not-fetch-unknown-profiles";
public static final String CHECK_IPS_CODES = "-check-ips-codes";
public static final String BEST_PRACTICE = "-best-practice";

Expand Down Expand Up @@ -270,6 +271,8 @@ else if (args[i].equals(HTML_OUTPUT)) {
cliContext.setNoExtensibleBindingMessages(true);
} else if (args[i].equals(ALLOW_DOUBLE_QUOTES)) {
cliContext.setAllowDoubleQuotesInFHIRPath(true);
} else if (args[i].equals(DO_NOT_FETCH_UNKNOWN_PROFILES)) {
cliContext.setDoNotFetchUnknownProfiles(true);
} else if (args[i].equals(CHECK_IPS_CODES)) {
cliContext.setCheckIPSCodes(true);
} else if (args[i].equals(NO_UNICODE_BIDI_CONTROL_CHARS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
import org.hl7.fhir.r5.elementmodel.Manager;
import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.test.utils.TestingUtilities;
import org.hl7.fhir.r5.utils.validation.constants.BestPracticeWarningLevel;
import org.hl7.fhir.utilities.TimeTracker;
import org.hl7.fhir.utilities.VersionUtil;
import org.hl7.fhir.utilities.i18n.I18nConstants;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity;
import org.hl7.fhir.validation.ValidationEngine;
import org.hl7.fhir.validation.cli.model.CliContext;
import org.hl7.fhir.validation.cli.model.FileInfo;
import org.hl7.fhir.validation.cli.model.ValidationRequest;
import org.hl7.fhir.validation.cli.model.ValidationResponse;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -218,6 +223,64 @@ public void generateSnapshotMultipleSource() throws Exception {

}

@Test
@DisplayName("Test that CliContext.doNotFetchUnknownProfiles is handled correctly")
public void testDoNotFetchUnknownProfiles() throws Exception {
TestingUtilities.injectCorePackageLoader();
ValidationService myService = new ValidationService();

// a Patient resource profiled with http://hl7.org/fhir/us/mcode/StructureDefinition/mcode-cancer-patient
// https://github.com/FHIR/fhir-test-cases/blob/master/validator/mcode-pat.json
String resource = TestingUtilities.loadTestResource("validator", "mcode-pat.json");

List<FileInfo> filesToValidate = new ArrayList<>();
filesToValidate.add(new FileInfo().setFileName("test_resource.json")
.setFileContent(resource)
.setFileType(Manager.FhirFormat.JSON.getExtension()));
CliContext cliContext = new CliContext().setTxServer(null)
.setSv("4.0.1")
.setBestPracticeLevel(BestPracticeWarningLevel.Ignore);

ValidationRequest request = new ValidationRequest().setCliContext(cliContext).setFilesToValidate(filesToValidate);
ValidationResponse response = myService.validateSources(request);

// Scenario 1: default behavior, doNotFetchUnknownProfiles is "false"
// -- this resource validates with no warnings or errors
response.getOutcomes().get(0).getMessages().forEach(m -> {
if (m.getLevel() == IssueSeverity.WARNING || m.getLevel() == IssueSeverity.ERROR) {
fail();
}
});

// Scenario 2: doNotFetchUnknownProfiles is "true"
// -- now there is a warning that the profile was not fetched
cliContext.setDoNotFetchUnknownProfiles(true);
response = myService.validateSources(request);

boolean found = false;
for (ValidationMessage m : response.getOutcomes().get(0).getMessages()) {
if (m.getLevel() == IssueSeverity.WARNING &&
m.getMessageId() == I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN_NOT_POLICY) {
// "Profile reference '...' has not been checked because it could not be found,
// and the validator is set to not fetch unknown profiles"
found = true;
break;
}
}
Assertions.assertTrue(found);

// Scenario 3: doNotFetchUnknownProfiles is "false" and the relevant IG is added to context
// -- this resource again validates with no warnings or errors
cliContext.addIg("hl7.fhir.us.mcode#1.0.0");
response = myService.validateSources(request);

response.getOutcomes().get(0).getMessages().forEach(m -> {
if (m.getLevel() == IssueSeverity.WARNING || m.getLevel() == IssueSeverity.ERROR) {
fail();
}
});
}

private CliContext getCliContextSingleSource() {
CliContext cliContext;
cliContext = new CliContext().setSources(Arrays.asList(DUMMY_SOURCE));
Expand Down

0 comments on commit 8bfba3d

Please sign in to comment.