Search in sources :

Example 51 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project dpc-app by CMSgov.

the class ValidationHelpers method validateAgainstProfile.

/**
 * Validates the provided {@link Resource} against the given Profile
 *
 * @param validator  - {@link FhirValidator} to use for validation
 * @param params     - {@link Parameters} to get resource from
 * @param profileURL - {@link String} profile URL to use for validation
 * @return - {@link IBaseOperationOutcome} outcome with failures (if any)
 */
public static IBaseOperationOutcome validateAgainstProfile(FhirValidator validator, Parameters params, String profileURL) {
    final Resource resource = params.getParameterFirstRep().getResource();
    final ValidationOptions valOps = new ValidationOptions();
    final ValidationResult validationResult = validator.validateWithResult(resource, valOps.addProfile(profileURL));
    return validationResult.toOperationOutcome();
}
Also used : Resource(org.hl7.fhir.dstu3.model.Resource) ValidationOptions(ca.uhn.fhir.validation.ValidationOptions) ValidationResult(ca.uhn.fhir.validation.ValidationResult)

Example 52 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project synthea by synthetichealth.

the class HospitalExporterTestDstu2 method testFHIRExport.

@Test
public void testFHIRExport() throws Exception {
    FhirContext ctx = FhirDstu2.getContext();
    FhirValidator validator = ctx.newValidator();
    validator.setValidateAgainstStandardSchema(true);
    validator.setValidateAgainstStandardSchematron(true);
    File tempOutputFolder = tempFolder.newFolder();
    Config.set("exporter.baseDirectory", tempOutputFolder.toString());
    Config.set("exporter.hospital.fhir_dstu2.export", "true");
    Config.set("exporter.fhir.transaction_bundle", "true");
    // set this manually, in case it has already been loaded.
    FhirDstu2.TRANSACTION_BUNDLE = true;
    TestHelper.loadTestProperties();
    Generator.DEFAULT_STATE = Config.get("test_state.default", "Massachusetts");
    Location location = new Location(Generator.DEFAULT_STATE, null);
    Provider.clear();
    Provider.loadProviders(location, ProviderTest.providerRandom);
    assertNotNull(Provider.getProviderList());
    assertFalse(Provider.getProviderList().isEmpty());
    Provider.getProviderList().get(0).incrementEncounters(EncounterType.WELLNESS, 0);
    HospitalExporterDstu2.export(0L);
    File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir_dstu2").toFile();
    assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());
    File expectedExportFile = expectedExportFolder.toPath().resolve("hospitalInformation0.json").toFile();
    assertTrue(expectedExportFile.exists() && expectedExportFile.isFile());
    FileReader fileReader = new FileReader(expectedExportFile.getPath());
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    StringBuilder fhirJson = new StringBuilder();
    String line = null;
    while ((line = bufferedReader.readLine()) != null) {
        fhirJson.append(line);
    }
    bufferedReader.close();
    IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson.toString());
    ValidationResult result = validator.validateWithResult(resource);
    if (result.isSuccessful() == false) {
        for (SingleValidationMessage message : result.getMessages()) {
            System.out.println(message.getSeverity().toString() + ": " + message.getMessage());
        }
    }
    assertTrue(result.isSuccessful());
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) SingleValidationMessage(ca.uhn.fhir.validation.SingleValidationMessage) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) FhirValidator(ca.uhn.fhir.validation.FhirValidator) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ValidationResult(ca.uhn.fhir.validation.ValidationResult) File(java.io.File) Location(org.mitre.synthea.world.geography.Location) Test(org.junit.Test) ProviderTest(org.mitre.synthea.world.agents.ProviderTest)

Example 53 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project kindling by HL7.

the class BuildWorkerContext method verifyCode.

private ValidationResult verifyCode(CodeSystem cs, String code, String display) throws Exception {
    ConceptDefinitionComponent cc = findCodeInConcept(cs.getConcept(), code);
    if (cc == null)
        return new ValidationResult(IssueSeverity.ERROR, "Unknown Code " + code + " in " + cs.getUrl());
    if (display == null)
        return new ValidationResult(cc);
    CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
    if (cc.hasDisplay()) {
        b.append(cc.getDisplay());
        if (display.equalsIgnoreCase(cc.getDisplay()))
            return new ValidationResult(cc);
    }
    for (ConceptDefinitionDesignationComponent ds : cc.getDesignation()) {
        b.append(ds.getValue());
        if (display.equalsIgnoreCase(ds.getValue()))
            return new ValidationResult(cc);
    }
    return new ValidationResult(IssueSeverity.ERROR, "Display Name for " + code + " must be one of '" + b.toString() + "'");
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ConceptDefinitionDesignationComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 54 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project kindling by HL7.

the class BuildWorkerContext method verifyUcum.

private ValidationResult verifyUcum(String code, String display) {
    String s = ucum.validate(code);
    if (s != null) {
        System.out.println("UCUM eror: " + s);
        return new ValidationResult(IssueSeverity.ERROR, s);
    } else {
        ConceptDefinitionComponent def = new ConceptDefinitionComponent();
        def.setCode(code);
        def.setDisplay(ucum.getCommonDisplay(code));
        return new ValidationResult(def);
    }
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)

Example 55 with ValidationResult

use of org.hl7.fhir.r5.context.IWorkerContext.ValidationResult in project redmatch by aehrc.

the class RedmatchGrammarValidator method validateCode.

private ValidationResult validateCode(String code, String path, String message) throws IOException {
    // Special case: codes ending with extension.url
    if (code.endsWith("extension.url")) {
        code = code.substring(0, code.length() - 4);
    }
    Boolean res = null;
    Parameters out = terminologyService.validate(fhirPackage, code);
    for (ParametersParameterComponent param : out.getParameter()) {
        if (param.getName().equals("result")) {
            res = ((BooleanType) param.getValue()).getValue();
        }
    }
    if (res == null) {
        throw new RuntimeException("Unexpected response (has no 'result' out parameter).");
    }
    ValidationResult vr = new ValidationResult(res, code);
    if (!res) {
        vr.getMessages().add(String.format(message, path));
    }
    return vr;
}
Also used : ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)32 IOException (java.io.IOException)22 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)17 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)15 FileNotFoundException (java.io.FileNotFoundException)14 ValidationResult (ca.uhn.fhir.validation.ValidationResult)12 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)12 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)10 ValidationResult (org.hl7.fhir.r4b.context.IWorkerContext.ValidationResult)10 ArrayList (java.util.ArrayList)9 Coding (org.hl7.fhir.r5.model.Coding)9 NotImplementedException (org.apache.commons.lang3.NotImplementedException)7 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)7 ValidationResult (org.hl7.fhir.r4.context.IWorkerContext.ValidationResult)7 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)7 FHIRLexerException (org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)7