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();
}
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());
}
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() + "'");
}
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);
}
}
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;
}
Aggregations